package com.bestdreamer.transdata;

public class Demo1ThreadB extends Thread {

    private final Object lock;

    public Demo1ThreadB(Object lock){
        super();
        this.lock = lock;
    }

    @Override
    public void run() {
        try{
            synchronized (lock){
                for( int i = 0; i < 10; i++){
                    Demo1MyList.add();
                    if(Demo1MyList.size() == 5){
                        lock.notify();
                        System.out.println("已发出通知");
                    }
                    System.out.println("添加了 " + (i+1)+" 个元素！");
                    Thread.sleep(1000);
                }
            }
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }
}
